package org.bp.util;

import java.util.regex.Pattern;

public class RegularUtils {
	private static final Pattern VALIDSTR = Pattern.compile("[\\w\\d\\u4E00-\\u9FA5]+");
    private static final Pattern VALIDPHONE = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
    private static final Pattern VALIDEMAIL = Pattern.compile("^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*" +
            "@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$");
    
    /**
     * 判断是否包含非法字符、特殊字符
     */
    public static boolean isValidChar(String str) {
        return VALIDSTR.matcher(str).matches();
    }

    /**
     * 验证邮箱格式是否合法
     * @param email 邮箱名
     * @return 是否合法
     */
    public static boolean isValidEmail(String email) {
        return VALIDEMAIL.matcher(email).matches();
    }

    /**
     * 验证手机号是否合法
     * @param phone 手机号
     * @return 是否合法
     */
    public static boolean isValidPhone(String phone) {
        return VALIDPHONE.matcher(phone).matches();
    }
}
